package zzg.study.serialize.impl;

import com.alibaba.fastjson.JSON;
import zzg.study.serialize.Serializer;
import zzg.study.serialize.SerializerAlgorithm;

/**
 * @Classname Serializer
 * @Description 使用最简单的JSON序列化方式，将阿里巴巴的Fastjson作为序列化框架
 * @Date 2023/11/28 21:53
 * @Author zhuzhenguo
 */
public class JSONSerializer implements Serializer {

    @Override
    public byte getSerializerAlgorithm() {
        return SerializerAlgorithm.JSON;
    }

    @Override
    public byte[] serialize(Object object) {
        return JSON.toJSONBytes(object);
    }

    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) {
        return JSON.parseObject(bytes, clazz);
    }
}
